package main

import (
	"encoding/gob"
	"fmt"
	"log"
	"os"
)

type Address struct {
	Type    string
	City    string
	Country string
}

type VCard struct {
	FirstName string
	LastName  string
	Addresses []*Address
	Remark    string
}

//创建一个解码vcard.gob文件的解码器
func main() {
	//创建打开文件
	output, err := os.Open("vcard.gob")
	if err != nil {
		fmt.Println("Open file fail!")
	}
	defer output.Close()
	//创建编码器
	enc := gob.NewDecoder(output)
	var vcard VCard
	error := enc.Decode(&vcard)
	if error != nil {
		log.Fatal("decode error:", error)
	}
	fmt.Println(vcard.Addresses[1], vcard.Addresses[0], vcard.LastName, vcard.LastName, vcard.Remark)
}
